package servlet.admin;

import entity.AdoptAnimal;
import service.AdoptService;
import service.Impl.AdoptServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/admin/DisAgreeFindByName")
public class DisAgreeFindByNameServlet extends HttpServlet {
    private AdoptService adoptService = new AdoptServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        List<AdoptAnimal> adoptList = adoptService.finfByUsername(username); // 确保方法返回List<AdoptAnimal>
        StringBuilder htmlBuilder = new StringBuilder();
        for (AdoptAnimal adopt : adoptList) {
            htmlBuilder.append("<p>用户名称: ").append(adopt.getUser().getUserName())
                    .append(", 宠物名字: ").append(adopt.getPet().getPetName())
                    .append(", 领养时间: ").append(adopt.getAdoptTime())
                    .append("</p>");
        }
        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().write(htmlBuilder.toString());
    }
}
